package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;
	private Recipe r5;

	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		
		r2 = new Recipe();
		r2.setName("ColdCoffee");
		r2.setPrice(70);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(1);
		r2.setAmtSugar(1);
		r2.setAmtChocolate(0);
		
		r3 = new Recipe();
		r3.setName("IceCoffee");
		r3.setPrice(40);
		r3.setAmtCoffee(2);
		r3.setAmtMilk(1);
		r3.setAmtSugar(1);
		r3.setAmtChocolate(0);
		
		r4 = new Recipe();
		r4.setName("VanilaCoffee");
		r4.setPrice(30);
		r4.setAmtCoffee(3);
		r4.setAmtMilk(2);
		r4.setAmtSugar(1);
		r4.setAmtChocolate(0);
		
		
	}
     //Test to add recipe in the machine
	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
		assertTrue(cm.addRecipe(r2));
		assertTrue(cm.addRecipe(r3));
		assertTrue(cm.addRecipe(r4));
	}
	
	//Test to add more recipe in the machine when the machine is full
	
	public void testAddRecipe2() {
		
		 cm.addRecipe(r1);
         cm.addRecipe(r2);
         cm.addRecipe(r3);
         cm.addRecipe(r4);
		
		r5 = new Recipe();
		r5.setName("Mangocoffee");
		r5.setPrice(10);
		r5.setAmtCoffee(2);
		r5.setAmtMilk(1);
		r5.setAmtSugar(1);
		r5.setAmtChocolate(0);
		assertFalse(cm.addRecipe(r5));
	}
//Test to add a recipe once a recipe has already been there in the machine
	 public void testAddRecipe3() {
         r3 = new Recipe();
         r3.setName("BlackCoffee");
         r3.setPrice(15);
         r3.setAmtCoffee(1);
         r3.setAmtMilk(2);
         r3.setAmtSugar(1);
         r3.setAmtChocolate(2);
         assertTrue(cm.addRecipe(r3));
         assertFalse(cm.addRecipe(r3));
 }

	//Test to delete recipe from the machine	
	
	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}
	//test to delete recipe which is not present there in coffeemaker
	public void testDeleteRecipe2() {
		
		assertFalse(cm.deleteRecipe(r5));
	}
	//Test whether to check that recipe is deleted when the price is less than 1
	 public void testDeleteRecipe3() {
         Recipe r = new Recipe(); 
         r.setPrice(-1);
         cm.addRecipe(r);
         assertFalse(cm.deleteRecipe(r));
	 }
	 
//Test to edit a recipe already there in the vending machine
	
	public void testEditRecipe1() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
		
		
		}
	//When the recipe is same it doesn't get edited
	public void testEditRecipe3() {
		cm.addRecipe(r2);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtMilk(2);
		 assertFalse(cm.editRecipe(r1, newRecipe));
	}
	
	//This test is to get recipe which we want
	 public void testRecipes()
     {
             Recipe[] recipe = new Recipe[2];
             r2 = new Recipe();
             r2.setName("ColdCoffee");
             r2.setPrice(70);
             r2.setAmtCoffee(3);
             r2.setAmtMilk(1);
             r2.setAmtSugar(1);
             r2.setAmtChocolate(0);
             recipe[0]=r2;
             
             assertFalse(recipe.equals(cm.getRecipes()));
     
     }
	
	
	//Test to edit a recipe already there in the vending machine with the different name
	 public void testEditRecipe2() {
         
        // Adding a recipe to coffeemaker
         cm.addRecipe(r3); 
         
         //Making a recipe object with name StrongCoffee
         Recipe r2 = new Recipe(); 
         r2.setName("StrongCoffee");
         r2.setPrice(45);
         r2.setAmtCoffee(1);
         r2.setAmtMilk(4);
         r2.setAmtSugar(1);
         r2.setAmtChocolate(1);
         
         assertFalse(cm.editRecipe(r3, r2));
         
}
	 public void testEditRecipe7() {
         
	        // Adding a recipe to coffeemaker
	         cm.addRecipe(r3); 
	         
	         //Making a recipe object with name StrongCoffee
	         Recipe r2 = new Recipe(); 
	         r2.setName("");
	         r2.setPrice(45);
	         r2.setAmtCoffee(1);
	         r2.setAmtMilk(4);
	         r2.setAmtSugar(1);
	         r2.setAmtChocolate(1);
	         
	         assertFalse(cm.editRecipe(r3, r2));
	         
	}
	 
	 
	 
	 //Test to purchase coffee
	  public void testPurchaseCoffee()
      {               

              assertEquals(cm.makeCoffee(r1, 3),3);
      }
	  public void testEditRecipe4() {
          assertFalse(cm.editRecipe(r3,r5));
  }
	  
	  
	  //Adding in the coffeemaker with positive values
	    public void testAddInventory() {
            
            assertTrue(cm.addInventory(2, 1, 0, 0));  
    }

//When negative value or someother value is added it will give error
public void testAddInventory1() {
            
            assertFalse(cm.addInventory(2, 1, -1, -1));
            assertTrue(cm.addInventory(2, 1, -1, 1)); 
            
    }
public void testAddInventory2() {
    i.setChocolate(-9);
    i.setSugar(-9);
    i.setMilk(-9);
    i.setCoffee(-9);
    assertFalse(cm.addInventory(-2, 1, -1, -1));  
}
public void testAddInventory3() {
    
    assertFalse(cm.addInventory(-2, -1, -1, -1));  
}
public void testAddInventory4() {
    
    assertFalse(cm.addInventory(-2,- 1, 1, 1));  
}
public void testAddInventory5() {
    
    assertFalse(cm.addInventory(-2,- 1, -1, 1));  
}


//Check when the price is less than the price of the coffee
public void testMakeCoffee1() {
    
    cm.addRecipe(r1);  
    assertEquals(30, cm.makeCoffee(r1, 30));  
}
//Check when the price is equal the price of the coffee
public void testMakeCoffee2() {
    
    cm.addRecipe(r1);  
    assertEquals(0, cm.makeCoffee(r1, 50));  
}

//Check when the price is more than the price of the coffee
public void testMakeCoffee3() {
    cm.addRecipe(r1);  
    assertEquals(20, cm.makeCoffee(r1, 70));  
}

//Checking to make coffee with the inventory
public void testMakeCoffee4()
{       i=cm.checkInventory();
        assertEquals(0, cm.makeCoffee(r1, 50));
        assertEquals(i.getChocolate(),15);
        assertEquals(i.getMilk(),14);
        assertEquals(i.getCoffee(),21);
        assertEquals(i.getSugar(),14);
}

//Test to get the name of the recipe
public void testGetRecipeForName(){
    cm.addRecipe(r3);
    Recipe newRecipe = new Recipe();
    newRecipe = r3;
    r3.setName("HotCoffee");
    String name="HotCoffee";
    cm.getRecipeForName(name);
    
    
    
}


    
    
}











